package me.banxi.mia.account.email;

import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

import org.springframework.core.io.ClassPathResource;
import org.springframework.mail.javamail.MimeMessageHelper;

public class BuildTemplateMimeMessage {

	public static 	MimeMessageHelper msgHelper;
	
	public static MimeMessage getMimeMessage(String to, MimeMessage mimeMessage) throws IOException{
		 try {
			msgHelper = new MimeMessageHelper(mimeMessage,true,"UTF-8");
			msgHelper.setTo(to);
			msgHelper.setSubject("你当我是浮夸吧!t1");
		InputStream is=	new ClassPathResource("mail_template/fukua.htm").getInputStream();
		StringBuilder sb = new StringBuilder();
		Scanner input = new Scanner(is);
		while(input.hasNext()){
			sb.append(input.nextLine());
		}
		
		
		    msgHelper.setText(sb.toString(),true);
		msgHelper.addInline("header_bg_night.jpg", new ClassPathResource("images/header_bg_night.jpg"));
		msgHelper.addInline("list.png", new ClassPathResource("images/list.png"));
			

			
		} catch (MessagingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 return mimeMessage;
	}

}

/***
java.lang.NullPointerException
at org.springframework.mail.javamail.MimeMessageHelper.createMimeMultiparts(MimeMessageHelper.java:343)
at org.springframework.mail.javamail.MimeMessageHelper.<init>(MimeMessageHelper.java:289)
at org.springframework.mail.javamail.MimeMessageHelper.<init>(MimeMessageHelper.java:246)
at me.banxi.mia.account.email.BuildTemplateMimeMessage.getMimeMessage(BuildTemplateMimeMessage.java:19)
at me.banxi.mia.account.email.AccountEmailServiceImpl.sendMail(AccountEmailServiceImpl.java:44)
at me.banxi.mia.account.email.AccountEmailServiceTest.testSendMail(AccountEmailServiceTest.java:29)

**/